package com.uyaer.engine
{
	import com.uyaer.engine.core.Tick;
	import com.uyaer.engine.display.Camera;
	import com.uyaer.engine.display.Scene;
	import com.uyaer.engine.plug.Keybord;
	
	import flash.display.Stage;
	import flash.external.ExternalInterface;
	import flash.net.sendToURL;

	public class Engine
	{
		private static var myinstance:Engine = new Engine();
		private var keybord:Keybord;
		public var ticker:Tick;
		public var scene:Scene;
		public var camera:Camera;
		public var stage:Stage;
		public function Engine()
		{
		}
		
		public static function get instance():Engine{
			return myinstance;
		}
		
		/**
		 *运行引擎 
		 * @param _stage
		 * @return 
		 * 
		 */		
		public function start(_stage:Stage):Engine{
			stage = _stage;
			ExternalInterface.call("ue_focusMe");
			register();
			return instance;
		}
		
		private function register():void{
			scene = new Scene(stage);
			camera = new Camera();
			camera.bind(this);
			keybord = new Keybord();
			ticker = new Tick();
			
			ExternalInterface.addCallback("windowResize",onWindowResize)
		}
		
		private function onWindowResize():void{
			camera.resize();
		}
	}
}